package functionHelper;

import java.util.ArrayList;

import controller.*;
import dataObject.Brand;
import exception.UserSelectionOutOfRangeException;

public class ProductLister {
	private IOPrinter printer;
	public ProductLister()
	{
		printer=IOPrinter.getPrinter();
	}
	public void listProduct(String userInput,ArrayList<Brand> brandList) throws UserSelectionOutOfRangeException
	{
		String[] brands = userInput.split(",");
		if(brands[0].equals("all")||brands[0].equals("All")||brands[0].equals("ALL"))
		{
			printer.printProductFormat();
			for(Brand b:brandList)
			{
				printer.print(b.getName()+" :");
				b.printProductList();
			}
		}
		else
		{
			for(int j=0;j<brands.length;j++)
			{
				for(int i=0;i<brandList.size();i++)
				{
					if(Integer.parseInt(brands[j])>brandList.size())
						throw new UserSelectionOutOfRangeException();
					if(Integer.parseInt(brands[j])-1==i)
					{
						printer.print(brandList.get(i).getName()+" :");
						brandList.get(i).printProductList();
					}
				}
			}
		}
	}
}
